<template>
  <el-dialog title="修改管理员密码" :visible.sync="dialogVisible" width="800px" v-drag-dialog append-to-body>
    <div style="max-height: 520px;overflow: auto;">
      <el-scrollbar style="height:100%;">
        <el-form :model="fin"  ref="ruleForm" label-width="100px" size="small">
          <el-form-item label="旧密码" prop="name">
            <el-input type="password" v-model="fin.oldPassword"></el-input>
          </el-form-item>
          <el-form-item label="新密码" prop="name">
            <el-input type="password" v-model="fin.password1"></el-input>
          </el-form-item>
          <el-form-item label="确认新密码" prop="name">
            <el-input type="password" v-model="fin.password"></el-input>
          </el-form-item>
        </el-form>
      </el-scrollbar>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="resetForm('fintructor')" size="small">取消</el-button>
      <el-button type="primary" @click="save" size="small">确认修改</el-button>
    </span>
  </el-dialog>
</template>

<script>
import {saveOrUpdate} from "@/api/login"
import { getSession ,clearSession} from "@/utils/storage";
import {resetRouter} from "@/router";
export default {
  name: "homeUserSetDialog",
  data() {
    return {
      fin: {
        id:'',
        oldPassword:'',
        password1:'',
        password:''
      },

      dialogVisible: false,
    };
  },
  mounted() {
    this.getUserInfo();
  },
  methods: {
    //获取缓存
    getUserInfo(){
      this.fin.id=getSession('userInfo').finstructor.id;
    },
    save(){
      if (this.fin.password1!=this.fin.password){
        alert("两次密码输入不一致")
        return;
      }
      saveOrUpdate(this.fin).then(res=> {
        clearSession();
        this.$store.commit('setMenuData', {});
        resetRouter()  // 重置路由
        this.$router.push('/login');
        setTimeout(() => {
          this.$message.success("操作成功！记得回来哟~");
        }, 300);
      }).catch(() => { });

    },
    // 打开
    open() {
      this.dialogVisible = true;
    },
    // 关闭
    close() {
      this.dialogVisible = false;
    },

    // 表单重置
    resetForm(formName) {
      this.fin = {
        id:'',
        oldPassword:'',
        password1:'',
        password:''
      }
      this.close();
    },
  },
};
</script>

